package com.yidu.ladder.system.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.ladder.system.domain.Resource;
import com.yidu.ladder.system.domain.ResourceVo;
import com.yidu.ladder.system.service.ResourceService;


/**
 * 资源控制器
 * @author ld
 *
 */
@Controller
@RequestMapping("/system/resource")
public class ResourceController {
	
	/** 关联业务逻辑层 */
	@javax.annotation.Resource
	private ResourceService resourceService;
	
	/**
	 * 查询所有资源
	 * @param resourceVo
	 * @return
	 */
	@RequestMapping(value = "/resources", method = RequestMethod.GET)
	@ResponseBody
	public List<ResourceVo> queryAllResource(ResourceVo resourceVo) {
		//查询所有资源 带分页
		List<ResourceVo> resourceVoList = resourceService.findResourceSelective(resourceVo);
		return resourceVoList;
	}
	
	/**
	 * 查询资源懒加载方式
	 * @param resourceId
	 * @return
	 */
	@RequestMapping(value = "/resourcesLazy", method = RequestMethod.POST)
	@ResponseBody
	public List<ResourceVo> resourcesLazy(String resourceId) {
		//查询该资源的所有子资源方法
		List<ResourceVo> queryResourceLazy = resourceService.queryAllChildResource(resourceId);
		return queryResourceLazy;
	}
	
	/**
	 * 添加资源
	 * @param resource
	 * @return
	 */
	@RequestMapping(value = "/resource", method = RequestMethod.POST)
	@ResponseBody
	public boolean addResource(Resource resource) {
		//添加资源方法
		boolean result = resourceService.addResource(resource);
		return result;
	}
	
	/**
	 * 删除资源
	 * @param resourceIds
	 * @return
	 */
	@RequestMapping(value = "/resource", method = RequestMethod.DELETE)
	@ResponseBody
	public boolean removeResource(String[] resourceIds) {
		//删除资源方法
		boolean result = resourceService.removeResource(resourceIds);
		return result;
	}
	
	/**
	 * 修改资源
	 * @param resource
	 * @return
	 */
	@RequestMapping(value = "/resource", method = RequestMethod.PUT)
	@ResponseBody
	public boolean updateResource(Resource resource) {
		//修改资源
		boolean result = resourceService.updateResource(resource);
		return result;
	}
	
}